package cn.com.chengmandian.bike.controller;

import cn.com.chengmandian.bike.model.EbPriceRule;
import cn.com.chengmandian.bike.model.vo.PriceRuleVo;
import cn.com.chengmandian.bike.service.IEbPriceRuleService;
import cn.com.chengmandian.core.web.pojo.AgentInfo;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.com.chengmandian.core.web.utils.LocalMapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "价格规则相关接口")
@RestController
@RequestMapping("/price/rule")
public class EbPriceRuleController {
    @Autowired
    private IEbPriceRuleService priceRuleService;

    @ApiOperation("获取价格规则(无需登录)")
    @GetMapping("/get")
    public AjaxResult<PriceRuleVo> get() {
        AgentInfo agentInfo = LocalMapUtil.getAgentInfo();
        Assert.notNull(agentInfo.getAreaId(), "缺少运营区");
        return AjaxResult.success(priceRuleService.getRule(agentInfo.getAreaId()));
    }

    @ApiOperation("区域价格规则(无需登录)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaId", value = "区域ID")
    })
    @GetMapping("/area")
    public AjaxResult<PriceRuleVo> areaPrice(Integer areaId) {
        Assert.notNull(areaId, "缺少运营区");
        return AjaxResult.success(priceRuleService.getRule(areaId));
    }
}
